package com.zhidan.mmtrade.common.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.zhidan.core.controller.LogController;
import com.zhidan.core.interceptor.CorsInterceptor;
import com.zhidan.core.log.interceptor.LogInterceptor;
import com.zhidan.mmtrade.controller.DemoController;
import com.zhidan.mmtrade.model.mapping._MappingKit;

public class MainConfig extends JFinalConfig {
	
	public MainConfig(){
		
	}
	
    @Override
    public void configConstant(Constants me) {
      me.setDevMode(true);//
    }

    @Override
    public void configRoute(Routes me) {
        me.addInterceptor(new CorsInterceptor());
        me.add("/", DemoController.class, "/");
		// include base controller in zhidan-bean:log,schedule
        me.add("/log", LogController.class, "/log");
	}

    @Override
    public void configPlugin(Plugins me) {
    	
    	loadPropertyFile("jdbc.properties");
    	DruidPlugin dsMysql = new DruidPlugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"),getProperty("driverClass"));
		dsMysql.setMaxActive(200);
		dsMysql.setInitialSize(3);
		dsMysql.setMinIdle(3);
		
		String datasouceName= getProperty("datasouceName");
		
    	me.add(dsMysql);
        //配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(datasouceName,dsMysql);
        // 导入基础的model, includes log, schedule
        com.zhidan.core.model._MappingKit.mapping(arp);
        // 导入service的model, includes order,goods, etc
        _MappingKit.mapping(arp);
        me.add(arp);
    }

    @Override
    public void configInterceptor(Interceptors me) {
		me.add(new LogInterceptor());
    }

    @Override
    public void configHandler(Handlers me) {

    }

	@Override
	public void afterJFinalStart(){
	}
	
	@Override
	public void beforeJFinalStop(){
		
	}

	@Override
	public void configEngine(Engine arg0) {
		// TODO Auto-generated method stub
		
	}
}
